package yxy.game.pm2.command.conquest;

import yxy.cherry.game.base.message.MessageEmitterHandler;
import yxy.cherry.game.base.message.annotation.MessageSource;
import yxy.cherry.game.base.message.annotation.MessageType;
import yxy.game.pm2.Result;
import yxy.game.pm2.command.Command;
import yxy.game.pm2.message.ConquestMessage;
import yxy.game.pm2.module.conquest.ConquestModule;

/** 征战 关卡扫荡 */
@MessageType(proto = Command.ConquestSweep, classtype = ConquestMessage.ConquestSweepRequest.class)
public class CMD_ConquestSweep extends Command<ConquestMessage.ConquestSweepRequest> {

	@Override
	public void execute(MessageSource messageSource, ConquestMessage.ConquestSweepRequest request) {
		String playerCode = messageSource.getTag();

		ConquestMessage.ConquestSweepResponse.Builder response = ConquestMessage.ConquestSweepResponse.newBuilder();

		ConquestModule conquestModule = ConquestModule.get(playerCode);
		int remain = conquestModule.remainsweeptimes();
		int times = conquestModule.sweeptimes();
		boolean privilege = conquestModule.isPrivilege();

		response.setTimes(times);
		response.setReleaseTimes(remain);
		response.setPrivilege(privilege);

		send(messageSource, response, Result.Success);
	}

	private void send(MessageSource messageSource, ConquestMessage.ConquestSweepResponse.Builder response, Result result) {
		response.setResult(result.packResult());
		MessageEmitterHandler.getInstance().send(messageSource, response.build());
	}
}